package com.neuedu.shop.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * @author MrDCG
 * @version 创建时间：2019年9月9日 下午3:48:11
 *
 */
public final class MybatisUtil {
	private MybatisUtil() {
	}

	public static SqlSession getSession(String resource) {
		InputStream inputStream;
		SqlSession session = null;
		try {
			inputStream = Resources.getResourceAsStream(resource);
			SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
			session = sqlSessionFactory.openSession();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return session;
	}
}
